import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LayoutView from '../views/Layout.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/RegisterView.vue')
  },
  {
    path: '/reset',
    name: 'reset',
    component: () => import('../views/ResetPassword.vue')
  },
  {
    path: '/',
    name: 'Layout',
    component: LayoutView,
    children: [
      {
        path: '',
        name: 'home',
        component: HomeView
      },
      {
        path: 'admin',
        name: 'admin',
        component: () => import('../views/AdminView.vue')
      },
      {
        path: 'tutor',
        name: 'tutor',
        component: () => import('../views/TutorView.vue')
      },
      {
        path: 'type',
        name: 'type',
        component: () => import('../views/TypeView.vue')
      },
      {
        path: 'hire',
        name: 'hire',
        component: () => import('../views/HireView.vue')
      },
      {
        path: 'thesis-teacher',
        name: 'thesis-teacher',
        component: () => import('../views/ThesisTeacherView.vue')
      },
      {
        path: 'thesis-student',
        name: 'thesis-student',
        component: () => import('../views/ThesisStudentView.vue')
      },
      {
        path: 'proposal',
        name: 'proposal',
        component: () => import('../views/ProposalView.vue')
      },
      {
        path: 'inspect',
        name: 'inspect',
        component: () => import('../views/InspectView.vue')
      },
      {
        path: 'communicate',
        name: 'communicate',
        component: () => import('../views/Communication.vue')
      },
      {
        path: 'log',
        name: 'log',
        component: () => import('../views/LogView.vue')
      },
      {
        path: 'notice',
        name: 'notice',
        component: () => import('../views/NoticeView.vue')
      },
      {
        path: 'chat',
        name: 'chat',
        component: () => import('../views/Im.vue')
      }
    ]
  },
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由守卫
router.beforeEach((to, from, next)=>{
 
  const user = localStorage.getItem("user");
  if(!user && (to.path!=='/login') &&(to.path != '/register') && (to.path != '/reset')){
    return next('/login');
  }
  next()
})



export default router
